package com.ybxy;

import java.util.ArrayList;
import java.util.Iterator;

public class Main {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("hello");
        list.add("world");
        list.add("java");
        list.add("programming");
        System.out.println("......第一种遍历方式......");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("......第二种遍历方式......");
        for (String str : list) {
            System.out.println(str);
        }
        System.out.println("......第三种遍历方式......");
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        System.out.println("......第四种遍历方式......");
        //list.forEach(s -> System.out.println(s));
        list.forEach(System.out::println);




    }
}